package cqrtplm.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hustcad.plm.pdm.flowbusiness.model.entity.FlowObject;
import com.hustcad.plm.pdm.flowbusiness.model.entity.WorkFlowObjectPackage;
import com.hustcad.plm.pdm.form.model.vo.TyplmFormDataVO;
import com.hustcad.plm.pdm.form.service.TyFormDataExtService;
import com.hustcad.plm.pdm.workflow.model.entity.WorkFlowContainerView;
import com.hustcad.plm.pdm.workflow.service.TyplmWorkFlowContainerService;
import com.ty.basic.entity.org.UserDO;
import com.ty.basic.service.snow.SnowflakeIdComponent;
import com.ty.basic.session.TyAccountContext;
import cqrtplm.adapter.OAAdapter;
import cqrtplm.entity.RtZdSqbDO;
import cqrtplm.entity.RtZdDbDO;
import cqrtplm.entity.RtZdMxbDO;
import cqrtplm.dto.RtZdInfoDTO;
import cqrtplm.entity.oa.FormMainDataModel;
import cqrtplm.entity.oa.FormSonDataModel;
import cqrtplm.entity.oa.OACreateRetEntity;
import cqrtplm.entity.oa.V80FlowDataModel;
import cqrtplm.mapper.RtZdMapper;
import cqrtplm.service.RtZdService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;

@Slf4j
@Service
public class RtZdServiceImpl implements RtZdService {
    @Resource
    private SnowflakeIdComponent snowflakeIdComponent;
    @Autowired
    private RtZdMapper rtZdMapper;
    @Autowired
    private TyplmWorkFlowContainerService typlmWorkFlowContainerService;
    @Autowired
    private OAAdapter oaAdapter;
    @Resource
    private TyFormDataExtService tyFormDataExtService;

    @Override
    public Map<String, Object> querySqb(Map<String, Object> params) {
        // 判断是否需要分页
        Integer pageNum = params.get("pageNum") != null ? 
            Integer.parseInt(params.get("pageNum").toString()) : null;
        Integer pageSize = params.get("pageSize") != null ? 
            Integer.parseInt(params.get("pageSize").toString()) : null;
        
        if (pageNum != null && pageSize != null) {
            PageHelper.startPage(pageNum, pageSize);
        }
        
        List<RtZdSqbDO> list = rtZdMapper.querySqb(params);
        
        Map<String, Object> result = new HashMap<>();
        if (pageNum != null && pageSize != null) {
            PageInfo<RtZdSqbDO> pageInfo = new PageInfo<>(list);
            result.put("total", pageInfo.getTotal());
            result.put("list", pageInfo.getList());
            result.put("pageNum", pageInfo.getPageNum());
            result.put("pageSize", pageInfo.getPageSize());
            result.put("pages", pageInfo.getPages());
        } else {
            result.put("list", list);
            result.put("total", list.size());
        }
        
        return result;
    }
    
    @Override
    public RtZdSqbDO getSqbDetail(String kid) {
        // 查询申请单主信息
        RtZdSqbDO sqb = rtZdMapper.getSqbByKid(kid);
        if (sqb != null) {
            // 查询关联的指定信息（从底表查询，因为数据是一样的）
            List<RtZdDbDO> dbList = rtZdMapper.getDbByMainKid(kid);
            List<RtZdInfoDTO> zdInfoList = new ArrayList<>();
            
            for (RtZdDbDO db : dbList) {
                RtZdInfoDTO dto = convertDbToDTO(db);
                zdInfoList.add(dto);
            }
            
            sqb.setZdInfoList(zdInfoList);
        }
        return sqb;
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String saveSqb(RtZdSqbDO sqb) {
        Date now = new Date();
        
        if (StringUtils.isEmpty(sqb.getKid())) {
            // 新增
            sqb.setKid(String.valueOf(snowflakeIdComponent.getInstance().nextId()));
            sqb.setFCreateDate(now);
            //sqb.setStatus(2); // 默认草稿状态
            rtZdMapper.insertSqb(sqb);
        } else {
            // 修改
            sqb.setFModifyDate(now);
            rtZdMapper.updateSqb(sqb);
            
            // 删除原有的指定信息
            rtZdMapper.deleteDbByMainKid(sqb.getKid());
            rtZdMapper.deleteMxbByMainId(sqb.getKid());
        }

        // 保存指定信息到两个表
        if (sqb.getZdInfoList() != null && !sqb.getZdInfoList().isEmpty()) {
            for (RtZdInfoDTO dto : sqb.getZdInfoList()) {
                // 生成共同的DetailID
                String detailId = String.valueOf(snowflakeIdComponent.getInstance().nextId()).toString();

                // 1. 保存到底表
                RtZdDbDO db = convertDTOToDb(dto);
                db.setAid(String.valueOf(snowflakeIdComponent.getInstance().nextId()).toString());
                db.setMainKid(sqb.getKid());
                db.setDetailId(detailId);  // 使用相同的DetailID
                db.setFCreateDate(now);
                db.setFCreateUserId(sqb.getFCreateUserId());
                db.setFCreateUserName(sqb.getFCreateUserName());
                db.setFCreateUserDepartment(sqb.getFDptNature());
                db.setStatus(1);
                db.setDeleteMark(0);
                db.setFactory(sqb.getFactory());

                db.setChangeType(dto.getChangeType());
                db.setMaterialCode(dto.getMaterialCode());
                db.setMaterialName(dto.getMaterialName());
                db.setAppointSupplier(dto.getSupplierCode());
                db.setSupplierDescription(dto.getSupplierDescription());
                db.setCustomerCode(dto.getCustomerCode());
                db.setCustomerName(dto.getCustomerName());
                db.setDevCode(dto.getDevCode());
                db.setBeginTime(dto.getBeginTime());
                db.setEndTime(dto.getEndTime());

                rtZdMapper.insertDb(db);

                // 2. 保存到明细表
                RtZdMxbDO mxb = convertDTOToMxb(dto);
                mxb.setDetailId(detailId);  // 使用相同的DetailID
                mxb.setMainId(sqb.getKid());
                mxb.setFCreateDate(now);
                mxb.setFCreateUserId(sqb.getFCreateUserId());
                mxb.setFCreateUserName(sqb.getFCreateUserName());
                mxb.setStatus(1);

                mxb.setChangeType(dto.getChangeType());
                mxb.setMaterialCode(dto.getMaterialCode());
                mxb.setPartName(dto.getMaterialName());
                mxb.setSupplierCode(dto.getSupplierCode());
                mxb.setSupplierName(dto.getSupplierDescription());
                mxb.setCustomerCode(dto.getCustomerCode());
                mxb.setCustomerName(dto.getCustomerName());
                mxb.setDevCode(dto.getDevCode());
                mxb.setBeginTime(dto.getBeginTime());
                mxb.setEndTime(dto.getEndTime());

                rtZdMapper.insertMxb(mxb);
            }
        }

        return sqb.getKid();
    }
    
    @Override
    @Transactional
    public boolean deleteSqb(String kid) {
        // 先删除指定信息
        rtZdMapper.deleteDbByMainKid(kid);
        rtZdMapper.deleteMxbByMainId(kid);
        // 再删除申请单
        int result = rtZdMapper.deleteSqb(kid);
        return result > 0;
    }
    
    @Override
    public Map<String, Object> queryZdInfo(Map<String, Object> params) {
        // 判断是否需要分页
        Integer pageNum = params.get("pageNum") != null ? 
            Integer.parseInt(params.get("pageNum").toString()) : null;
        Integer pageSize = params.get("pageSize") != null ? 
            Integer.parseInt(params.get("pageSize").toString()) : null;
        
        // 从底表查询（因为数据是一样的，只需要查询一个表即可）
        if (pageNum != null && pageSize != null) {
            PageHelper.startPage(pageNum, pageSize);
        }

        List<RtZdDbDO> dbList = rtZdMapper.queryDb(params);
        List<RtZdInfoDTO> dtoList = new ArrayList<>();
        for (RtZdDbDO db : dbList) {
            dtoList.add(convertDbToDTO(db));
        }
        
        Map<String, Object> result = new HashMap<>();
        if (pageNum != null && pageSize != null) {
            PageInfo<RtZdDbDO> pageInfo = new PageInfo<>(dbList);
            result.put("total", pageInfo.getTotal());
            result.put("list", dtoList);
            result.put("pageNum", pageInfo.getPageNum());
            result.put("pageSize", pageInfo.getPageSize());
            result.put("pages", pageInfo.getPages());
        } else {
            result.put("list", dtoList);
            result.put("total", dtoList.size());
        }
        
        return result;
    }
    
    // 转换方法：DB实体转DTO
    private RtZdInfoDTO convertDbToDTO(RtZdDbDO db) {
        RtZdInfoDTO dto = new RtZdInfoDTO();
        dto.setDetailId(db.getDetailId());
        dto.setChangeType(db.getChangeType());
        dto.setNoticeNo(db.getNoticeNo());
        dto.setCustomerCode(db.getCustomerCode());
        dto.setCustomerName(db.getCustomerName());
        dto.setDevCode(db.getDevCode());
        dto.setOrderNo(db.getOrderNo());
        dto.setOrderItemNo(db.getOrderItemNo());
        dto.setCategory(db.getCategory());
        dto.setMaterialCode(db.getMaterialCode());
        dto.setMaterialName(db.getMaterialName());
        dto.setSupplierCode(db.getAppointSupplier());  // 底表用AppointSupplier存供应商代码
        dto.setSupplierDescription(db.getSupplierDescription());
        dto.setBeginTime(db.getBeginTime());
        dto.setEndTime(db.getEndTime());
        dto.setProductType(db.getProductType());
        dto.setProduct(db.getProduct());
        dto.setStatus(db.getStatus());
        dto.setFormoid(db.getFormoid());
        return dto;
    }
    
    // 转换方法：DTO转DB实体
    private RtZdDbDO convertDTOToDb(RtZdInfoDTO dto) {
        RtZdDbDO db = new RtZdDbDO();
        db.setDetailId(dto.getDetailId());
        db.setChangeType(dto.getChangeType());
        db.setNoticeNo(dto.getNoticeNo());
        db.setCustomerCode(dto.getCustomerCode());
        db.setCustomerName(dto.getCustomerName());
        db.setDevCode(dto.getDevCode());
        db.setOrderNo(dto.getOrderNo());
        db.setOrderItemNo(dto.getOrderItemNo());
        db.setCategory(dto.getCategory());
        db.setMaterialCode(dto.getMaterialCode());
        db.setMaterialName(dto.getMaterialName());
        db.setAppointSupplier(dto.getSupplierCode());  // 供应商代码存到AppointSupplier
        db.setSupplierDescription(dto.getSupplierDescription());
        db.setBeginTime(dto.getBeginTime());
        db.setEndTime(dto.getEndTime());
        db.setProductType(dto.getProductType());
        db.setProduct(dto.getProduct());
        return db;
    }
    
    // 转换方法：DTO转MXB实体
    private RtZdMxbDO convertDTOToMxb(RtZdInfoDTO dto) {
        RtZdMxbDO mxb = new RtZdMxbDO();
        mxb.setDetailId(dto.getDetailId());
        mxb.setDevCode(dto.getDevCode());
        mxb.setPartsCode(dto.getPartsCode());
        mxb.setPartName(dto.getPartName());
        mxb.setMaterialCode(dto.getMaterialCode());
        mxb.setChangeType(dto.getChangeType());
        mxb.setAppointRangeType(dto.getAppointRangeType());
        mxb.setSupplierCode(dto.getSupplierCode());
        mxb.setSupplierName(dto.getSupplierName());
        mxb.setSupplyRate(dto.getSupplyRate());
        mxb.setSortOrder(dto.getSortOrder());
        mxb.setProductType(dto.getProductType());
        mxb.setAppointType(dto.getAppointType());
        mxb.setBeginTime(dto.getBeginTime());
        mxb.setEndTime(dto.getEndTime());
        mxb.setOrderNo(dto.getOrderNo());
        mxb.setOrderItemNo(dto.getOrderItemNo());
        mxb.setCustomerCode(dto.getCustomerCode());
        mxb.setCustomerName(dto.getCustomerName());
        mxb.setDeleteAid(dto.getDeleteAid());
        mxb.setOldMaterialCode(dto.getOldMaterialCode());
        mxb.setSourceAid(dto.getSourceAid());
        mxb.setFormoid(dto.getFormoid());
        return mxb;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void sendToOAFromWorkFlow(String workFlowContainerId) {
        // 1. 从流程对象中获取表单信息
        WorkFlowContainerView workFlowContainerView = typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(new BigInteger(workFlowContainerId));

        if (Objects.isNull(workFlowContainerView) || !(workFlowContainerView instanceof WorkFlowObjectPackage)) {
            throw new RuntimeException("流程对象不存在或类型不正确");
        }

        WorkFlowObjectPackage workFlowObjectPackage = (WorkFlowObjectPackage) workFlowContainerView;
        List<FlowObject> flowObjectList = workFlowObjectPackage.getFlowObjectList();
        String workFlowName = workFlowObjectPackage.getWorkFlowName();

        if (CollUtil.isEmpty(flowObjectList)) {
            throw new RuntimeException("流程对象列表为空");
        }

        // 2. 从表单信息中获取申请表单的id
        String applicationFormId = extractApplicationFormId(flowObjectList);
        if (StringUtils.isEmpty(applicationFormId)) {
            throw new RuntimeException("未找到申请表单ID");
        }

        // 3. 通过申请表单id获取申请表单信息及指定信息列表
        RtZdSqbDO sqbDetail = getSqbDetail(applicationFormId);
        if (Objects.isNull(sqbDetail)) {
            throw new RuntimeException("申请表单不存在，ID: " + applicationFormId);
        }

        // 4. 构造OA数据并发送
        sendApplicationToOA(sqbDetail, workFlowName);
    }

    /**
     * 从流程对象列表中提取申请表单ID
     */
    private String extractApplicationFormId(List<FlowObject> flowObjectList) {
        for (FlowObject flowObject : flowObjectList) {
            //TODO:提取申请表单ID
        }
        return null;
    }

    /**
     * 发送申请表单到OA系统
     */
    private void sendApplicationToOA(RtZdSqbDO sqbDetail, String workFlowName) {
        try {
            // 构造OA流程数据
            V80FlowDataModel flowData = buildOAFlowData(sqbDetail, workFlowName);

            // 调用OA接口
            OACreateRetEntity result = oaAdapter.CreateOAFlowV80(flowData, "指定申请发起OA", sqbDetail.getKid(), sqbDetail.getKid(), sqbDetail.getFCreateUserName());

            if (!"0".equals(result.getCode())) {
                throw new RuntimeException("OA接口调用失败: " + result.getMessage());
            }

            // 保存OA流程ID到本地（可选）
            if (result.getData() != null && result.getData().getAppbussinessdata() != null &&
                    !StringUtils.isEmpty(result.getData().getAppbussinessdata().getSummaryId())) {

                String oaFlowId = result.getData().getAppbussinessdata().getSummaryId();
                String errorMsg = result.getData().getErrorMsg();

                // 这里可以保存到数据库，记录OA流程ID
                // saveOAFlowRecord("指定申请", sqbDetail.getKid(), oaFlowId, errorMsg);
            }

        } catch (Exception e) {
            throw new RuntimeException("发送OA流程失败: " + e.getMessage(), e);
        }
    }

    /**
     * 构造OA流程数据
     */
    private V80FlowDataModel buildOAFlowData(RtZdSqbDO sqbDetail, String workFlowName) {
        V80FlowDataModel flowData = new V80FlowDataModel();

        // 设置基础信息
        flowData.setTemplateCode("T_OAFlow_ASSIGN_01"); // 根据实际模板编码调整
        //flowData.setSenderLoginName(sqbDetail.getFCreateUserOALoginName()); // 需要获取OA登录名
        flowData.setDraft("0"); // 0：发送，1：待发
        flowData.setAttachments(new ArrayList<>()); // 附件暂时为空，如需要可以处理

        // 构造标题
        String subject = String.format("%s %s %s 指定申请 %s",
                                       workFlowName,
                                       sqbDetail.getFCreateUserName());
        flowData.setSubject(subject);

        // 构造主表单数据
        FormMainDataModel mainForm = new FormMainDataModel();
        mainForm.setForm_name("formmain_13936"); // 根据实际表单名称调整

        Hashtable<String, Object> mainData = new Hashtable<>();
        mainData.put("申请日期", sqbDetail.getFCreateDate() != null ?
                new SimpleDateFormat("yyyy-MM-dd").format(sqbDetail.getFCreateDate()) : "");
        mainData.put("工厂", sqbDetail.getFactory());
        mainData.put("申请部门", sqbDetail.getFDptNature());
        //mainData.put("申请人", sqbDetail.()); // 需要OA用户ID
        //mainData.put("标题客户名称", sqbDetail.());
        mainData.put("申请单号", sqbDetail.getKid());
        mainData.put("DSPF发起人", sqbDetail.getFCreateUserName());

        mainForm.setForm_data(mainData);
        flowData.setMain_data(mainForm);

        // 构造子表单数据
        List<FormSonDataModel> sonDataList = new ArrayList<>();

        if (sqbDetail.getZdInfoList() != null && !sqbDetail.getZdInfoList().isEmpty()) {
            FormSonDataModel sonForm = new FormSonDataModel();
            sonForm.setForm_name("formson_13937"); // 根据实际子表名称调整

            List<Hashtable<String, Object>> sonRows = new ArrayList<>();
            for (RtZdInfoDTO zdInfo : sqbDetail.getZdInfoList()) {
                Hashtable<String, Object> row = new Hashtable<>();
                row.put("客户编码", zdInfo.getCustomerCode());
                row.put("客户名称", zdInfo.getCustomerName());
                row.put("开发令", zdInfo.getDevCode());
                row.put("物料编码", zdInfo.getMaterialCode());
                row.put("品名", zdInfo.getMaterialName());
                row.put("供应商编码", zdInfo.getSupplierCode());
                row.put("供应商名称", zdInfo.getSupplierDescription());
                row.put("指定类别", zdInfo.getAppointType());
                row.put("指定范围", zdInfo.getAppointRangeType());
                row.put("需求类型", zdInfo.getChangeType());
                row.put("指定开始日期", zdInfo.getBeginTime() != null ?
                        new SimpleDateFormat("yyyy-MM-dd").format(zdInfo.getBeginTime()) : null);
                row.put("指定终止日期", zdInfo.getEndTime() != null ?
                        new SimpleDateFormat("yyyy-MM-dd").format(zdInfo.getEndTime()) : null);
                row.put("订单范围", zdInfo.getOrderNo());
                row.put("采购比例", zdInfo.getSupplyRate());

                sonRows.add(row);
            }

            sonForm.setForm_data(sonRows);
            sonDataList.add(sonForm);
        }

        flowData.setSon_data(sonDataList);

        return flowData;
    }

    /**
     * 批量处理多个流程的OA发送
     */
    @Override
    public void batchSendToOAFromWorkFlow(List<String> workFlowContainerIds) {
        if (CollUtil.isEmpty(workFlowContainerIds)) {
            return;
        }

        List<String> successList = new ArrayList<>();
        List<String> failList = new ArrayList<>();

        for (String workFlowContainerId : workFlowContainerIds) {
            try {
                sendToOAFromWorkFlow(workFlowContainerId);
                successList.add(workFlowContainerId);
            } catch (Exception e) {
                failList.add(workFlowContainerId);
                // 记录错误日志
                log.error("发送工作流到OA失败，workFlowContainerId: {}, 错误信息: {}", workFlowContainerId, e.getMessage(), e);
            }
        }

        log.info("批量发送OA完成，成功: {}, 失败: {}", successList.size(), failList.size());
    }

    @Override
    public void saveApplicationFormData(String workFlowContainerId) {
        WorkFlowContainerView workFlowContainerView = typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(
                new BigInteger(workFlowContainerId));
        if (workFlowContainerView instanceof WorkFlowObjectPackage) {
            WorkFlowObjectPackage workFlowObjectPackage = (WorkFlowObjectPackage) workFlowContainerView;
            List<FlowObject> flowObjectList = workFlowObjectPackage.getFlowObjectList();
            for (FlowObject flowObject : flowObjectList) {
                BigInteger refObjectOid = flowObject.getRefObjectOid();
                TyplmFormDataVO formDataDetail = tyFormDataExtService.getFormDataDetail(refObjectOid);
                JSONObject json = formDataDetail.getFormdata();

                UserDO user = TyAccountContext.getUser();

                RtZdSqbDO rtZdSqbDO = new RtZdSqbDO();
                rtZdSqbDO.setFactory(json.getString("factory"));
                rtZdSqbDO.setStatus(1);
                rtZdSqbDO.setFCreateDate(new Date());
                rtZdSqbDO.setFCreateUserId(user.getOid().toString());
                rtZdSqbDO.setFCreateUserName(user.getFullname());

                JSONArray subform67098 = json.getJSONArray("subform67098");
                List<RtZdInfoDTO> zdInfoList=new ArrayList<>();
                for (int i = 0; i < subform67098.size(); i++) {
                    RtZdInfoDTO rtZdInfoDTO=new RtZdInfoDTO();

                    JSONObject jsonObject = subform67098.getJSONObject(i);
                    //变更类型
                    String input68758 = jsonObject.getString("input68758");
                    //客户编码
                    String input75631 = jsonObject.getString("input75631");
                    //客户名称
                    String input94778 = jsonObject.getString("input94778");
                    //物料编码
                    String input66947 = jsonObject.getString("input66947");
                    //物料名称
                    String input20325 = jsonObject.getString("input20325");
                    //供应商编码
                    String input80487 = jsonObject.getString("input80487");
                    //供应商名称
                    String input7629 = jsonObject.getString("input7629");
                    //结束时间
                    String input111716 = jsonObject.getString("input111716");

                    Integer j = rtZdMapper.selectExist(input68758, input75631, input66947, input80487);

                    if (j<1){
                        rtZdInfoDTO.setChangeType(input68758);
                        rtZdInfoDTO.setCustomerCode(input75631);
                        rtZdInfoDTO.setCustomerName(input94778);
                        rtZdInfoDTO.setMaterialCode(input66947);
                        rtZdInfoDTO.setMaterialName(input20325);
                        rtZdInfoDTO.setSupplierCode(input80487);
                        rtZdInfoDTO.setSupplierDescription(input7629);
                        rtZdInfoDTO.setBeginTime(LocalDateTime.now().toString());
                        rtZdInfoDTO.setEndTime(input111716);
                        rtZdInfoDTO.setFormoid(refObjectOid.toString());

                        zdInfoList.add(rtZdInfoDTO);
                    }else {

                        rtZdMapper.updateStatus(input68758, input75631, input66947, input80487);
                        rtZdMapper.updateStatus1(input68758,input75631,input66947,input80487);
                    }
                }
                if (zdInfoList.size()>0){
                    rtZdSqbDO.setZdInfoList(zdInfoList);
                    saveSqb(rtZdSqbDO);
                }
            }
        }
    }

    @Override
    public boolean checkExist(JSONObject jsonObject) {
        //客户编码
        String var1 = jsonObject.getString("CustomerCode");
        //开发令
        String var2 = jsonObject.getString("DevCode");
        //物料编码
        String var3 = jsonObject.getString("Category");
        //供应商编码
        String var4 = jsonObject.getString("AppointSupplier");
        //结束日期
        String var5 = jsonObject.getString("EndTime");
        //订单号
        String var6 = jsonObject.getString("OrderNo");
        //订单项次
        String var7 = jsonObject.getString("OrderItemNo");
        Integer i = rtZdMapper.checkExist(var1, var2, var3, var4, var5, var6, var7);
        return i<1?true:false;
    }

    @Override
    public void checkFormIdVersion(JSONObject jsonObject) {
        //客户编码
        String var1 = jsonObject.getString("CustomerCode");
        //开发令
        String var2 = jsonObject.getString("DevCode");
        //物料编码
        String var3 = jsonObject.getString("Category");
        //供应商编码
        String var4 = jsonObject.getString("AppointSupplier");
        //结束日期
        String var5 = jsonObject.getString("EndTime");

        List<String> ids=rtZdMapper.selectFormIds(var1,var2,var3,var4,var5);



//        rtZdMapper.updateMxbFormId(var1,var2,var3,var4,var5,ids);
    }
}